# coding:utf-8
# author:frank
# date:2024/12/31
import pygame

pygame.init()

win_w=500
win_h=600
win = pygame.display.set_mode((win_w,win_h))
pygame.display.set_caption("标题模板")
win.fill('white')
pygame.display.flip()

tank = pygame.image.load('files/tank_up.png')
tank = pygame.transform.scale(tank,(50,50))

vertical_down = False
horizontal_down = False
y = 300
x = 200
vertical = -0.1
horizontal = 0
win.blit(tank,(x,y))
pygame.display.update()
while True:
    if vertical_down:
        y += vertical
        win.fill('white')
        win.blit(tank, (x, y))
        pygame.display.update()
    if horizontal_down:
        x += horizontal
        win.fill('white')

        win.blit(tank, (x, y))
        pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
        if event.type == pygame.KEYDOWN:
            if 'w' == chr(event.key):
                tank = pygame.image.load('files/tank_up.png')
                tank = pygame.transform.scale(tank, (50, 50))
                vertical = -0.1
                vertical_down = True
            elif 's' == chr(event.key):
                tank = pygame.image.load('files/tank_down.png')
                tank = pygame.transform.scale(tank, (50, 50))
                vertical_down = True
                vertical = 0.1
            elif 'a' == chr(event.key):
                tank = pygame.image.load('files/tank_left.png')
                tank = pygame.transform.scale(tank, (50, 50))
                horizontal = -0.1
                horizontal_down = True
            elif 'd' == chr(event.key):
                tank = pygame.image.load('files/tank_right.png')
                tank = pygame.transform.scale(tank, (50, 50))
                horizontal = 0.1
                horizontal_down = True
        if event.type == pygame.KEYUP:
            if 'w' == chr(event.key) or 's' == chr(event.key):
                vertical_down = False

            if 'a' == chr(event.key) or 'd' == chr(event.key):
                horizontal_down = False